var EditPager = (function(){
	var DEF_SETTINGS = {
		container:null,
		is_submit:false,
		afterSuccess:function(){
			var _this= this;
			if(_this.container != null){
				if(!_this.is_submit){
					var jsonData = $(_this.container).serializeArray();	
					var url = $(_this.container).attr("action");
					$.ajax({
						url:url,
						data:jsonData,
						type:"POST",
						success:function(data){

						}
					});
				}
			}
		}
	}
	return {
		/*
			
			settings:{
				container:容器
				is_submit:false,
				param:function(){}
			}
		*/
		init:function(settings){
			var _this= this;
			if(settings.container == null){
				return;
			}
			var setting = $.extend({},DEF_SETTINGS, settings);

			var vform = $(setting.container).easyform();
			vform.is_submit = setting.is_submit;

			$(setting.container).find(".btn").on("click",function(){
				var tg = $(this).attr("tg");
				if(tg == "ensure"){
					vform.submit(setting.is_submit);
				}else if(tg == "cancel"){
					var index = parent.layer.getFrameIndex(window.name);
					parent.layer.close(index);
					parent.succflg = null;
				}
			});

			vform.success = function(ef){
				if(!setting.is_submit){
                    var jsonData;
                    if(setting.param){
                        jsonData = setting.param.call();
					}else{
                        jsonData = $(setting.container).serializeArray();
                    }
					var url = $(setting.container).attr("action");
					$.ajax({
						url:url,
						data:jsonData,
						type:"POST",
						success:function(data){
							if(data.success){
								layer.msg("更新成功",{},function(){
									var index = parent.layer.getFrameIndex(window.name);
									parent.layer.close(index);
									parent.succflg = 1;
								});
							}else{
								layer.msg(data.message);
							}
						}
					});
				}
			}
			vform.error=function (ex) {
				var j = 0;
			}
		}

	};
})();
